home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9811 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  75 lines

  1. Path: hops.cs.jhu.edu!lasher
  2. From: lasher@hops.cs.jhu.edu (John E. Davis)
  3. Newsgroups: comp.lang.c
  4. Subject: Do you see what is wrong?
  5. Date: 13 Mar 1996 18:01:10 GMT
  6. Organization: JHU computer science
  7. Message-ID: <4i72h6$2d4@blaze.cs.jhu.edu>
  8. NNTP-Posting-Host: hops.cs.jhu.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Can someone point out what is wrong with this snippet of code? 
  12. The problem is that I get a segmentation fault(core dumped) error when I 
  13. hit ^d to send end of file.  the error occurs at the place specified in 
  14. the code.  I would appreciate any/all ideas and any fixes that you might 
  15. suggest.  This was compiled on a system running some flavor of UNIX (not 
  16. sure which)
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22.  
  23. #define     SIZE    200
  24.  
  25. int closest(float [], float [], int [], float [], int);
  26. float distance(float, float, float, float);
  27.  
  28. void main()
  29. {
  30. float         xtemp, ytemp, Xposition[SIZE], Yposition[SIZE], totalLength[1];
  31. int         j = -1, n, i, distance, nextCoord, current = 0, status[SIZE];
  32.  
  33. totalLength[1] = 0;
  34.  
  35. /* variables not used in this section are used in other non-relevant 
  36. parts of the code */
  37.  
  38. printf("Enter coordinates in the form: x y\n ");
  39.  
  40. for( n = 0; n < SIZE; n++, j++ ) {
  41.     if( scanf("%f%f", &xtemp, &ytemp) != EOF) 
  42.         {
  43.         Xposition[n] = xtemp;
  44.         Yposition[n] = ytemp; 
  45.         }
  46.     else     {
  47.         printf("Done entering Numbers");  
  48.         n = SIZE; 
  49.         printf("\n%f %f", Xposition[j], Yposition[j]);
  50.         }  /*  <== I get a core dump right here. _after_ executing the 
  51. stuff in the else statemnet */ 
  52.     } 
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. --
  61.                               _____..---======+*+=======---.._____
  62.     __ ________________ __,-='=====____  ============== _____=====`=
  63.    (._I________________I__) - _-=_/    `------=+=-------'
  64.        /    /__...---==='---+---_'       jdavis@jhu.edu      
  65.       '----'---.___ - _ =   _.-'     lasher@hops.cs.jhu.edu
  66.                    `-------'      gargamel@jhunix.hcf.jhu.edu    
  67.        an461864@anon.penet.fi     gargamel@jhuvms.hcf.jhu.edu
  68.            (anonymous)
  69.  
  70. "To boldly go where no man has gone before... MY HOMEPAGE!! please visit..."
  71.                 http://hops.cs.jhu.edu/~lasher/
  72.  
  73. UNIX is a very user-friendly operating system ...
  74.             ... it's just picky about who it's friends with
  75.